package com.socialnetspace.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;

import com.socialnetspace.networks.ConnectFacebook;
import com.socialnetspace.networks.ConnectTwitter;
import com.socialnetspace.service.UserService;

@Controller
@RequestMapping(value="/service")
public class AjaxController {
	
	
	@Resource(name="UserService")
	private UserService userService;
	
	@Resource(name="ConnectTwitter")
	private ConnectTwitter connectTwitter;
	
	@Resource(name="ConnectFacebook")
	private ConnectFacebook connectFacebook;
	
	
	@RequestMapping(value="checkUsername", method=RequestMethod.POST)
	public @ResponseBody String checkUsername(String username) {
		
		userService.doUsernameExists(username);
		
		return null;
	}
	
	
	@RequestMapping(value="connectTwitter", method=RequestMethod.POST)
	public @ResponseBody String connectTwitter(WebRequest request) {
	
		String accessToken = request.getParameter("accessToken");
		String accessSecret = request.getParameter("accessSecret");
		
		connectTwitter.getTwitterProfile(accessToken, accessSecret);
		
		return null;
	}
	

	@RequestMapping(value="connectFacebook", method=RequestMethod.POST)
	public @ResponseBody String connectFacebook(WebRequest request) {
	
		String accessToken = request.getParameter("accessToken");
		
		connectFacebook.getFacebookProfile(accessToken);
		
		return null;
	}
	
	
}
